<%@ page import="util.PageController" %>
<%@ page import="dao.bis.BoardDao" %>
<%@ page import="dao.IBoardDao" %>
<%@ page import="java.util.List" %>
<%@ page import="entity.Board" %><%--
  Created by IntelliJ IDEA.
  User: Zard
  Date: 2019/4/7
  Time: 18:03
  To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<html>
  <head>
    <title></title>
  </head>
  <body>
<%
  String pageIndex = request.getParameter("pageIndex");
  if (pageIndex == null){
    pageIndex = "1";
  }
  int pageNum = Integer.parseInt(pageIndex);

  IBoardDao boardDao = new BoardDao();
  int boardCount = boardDao.getAllBoardCount();
  int totalPages = PageController.getTotalPages(boardCount,PageController.pageSize);

  if (pageNum < 1){
    pageNum = 1;
  }
  if (pageNum>totalPages){
    pageNum = totalPages;
  }
  List<Board> boardList = boardDao.getBoardByPage(pageNum,PageController.pageSize);
  for (Board b : boardList){
 %>
<%=b.getId()%>&nbsp;&nbsp;&nbsp;&nbsp;<%=b.getName()%><%out.print("<br>");%>
<%}%>

  <a href="index.jsp?pageIndex=1">首页</a>
  <a href="index.jsp?pageIndex=<%=pageNum-1%>">上一页</a>
  <a href="index.jsp?pageIndex=<%=pageNum+1%>">下一页</a>
  <a href="index.jsp?pageIndex=<%=totalPages%>">尾页</a>
  </body>
</html>
